package com.xy.controller.mainData;

import com.xy.api.model.dto.mainData.ProductDTO;
import com.xy.api.model.dto.mainData.VendorDTO;
import com.xy.api.model.dto.mainData.VendorProductTypeDTO;
import com.xy.api.model.request.mainData.VendorProductRequest;
import com.xy.api.model.request.mainData.VendorProductTypeRequest;
import com.xy.api.model.request.mainData.VendorRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.mainData.IProductService;
import com.xy.api.service.mainData.IVendorProductTypeService;
import com.xy.api.service.mainData.IVendorService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/vendor")
public class VendorController extends BaseController {

    @Autowired
    private IVendorService vendorService;

    @Autowired
    private IProductService productService;

    @Autowired
    private IVendorProductTypeService vendorProductTypeService;

    @PostMapping("/queryList")
    public R queryVendorList(@RequestBody VendorRequest request) {
        Rows<VendorDTO> rows = vendorService.queryVendorList(request);
        return success(rows);
    }

    @PostMapping("/queryAllList")
    public R queryAllVendorList() {
        Rows<VendorDTO> rows = vendorService.queryAllVendorList();
        return success(rows);
    }

    @PostMapping("/queryVendorProductList")
    public R queryVendorProductList(@RequestBody VendorProductRequest request) {
        Rows<ProductDTO> rows = productService.queryVendorProductList(request);
        return success(rows);
    }

    @PostMapping("/deleteVendorProduct")
    public R deleteVendorProduct(@RequestBody VendorProductRequest request) {
        vendorService.deleteVendorProduct(request);
        return success();
    }

    @PostMapping("/detail")
    public R<VendorDTO> vendorDetail(@RequestBody VendorRequest request) {
        VendorDTO vendor = vendorService.vendorDetail(request.getId());
        return success(vendor);
    }

    @PostMapping("/edit")
    public R<VendorDTO> editVendor(@RequestBody VendorDTO request) {
        VendorDTO vendor = vendorService.editVendor(request);
        return success(vendor);
    }

    @PostMapping("/delete")
    public R deleteVendor(@RequestBody VendorRequest request) {
        vendorService.deleteVendor(request.getId());
        return success();
    }

    @PostMapping("/productType/queryList")
    public R queryVendorProductTypeList(@RequestBody VendorProductTypeRequest request) {
        Rows<VendorProductTypeDTO> rows = vendorProductTypeService.queryVendorProductTypeList(request);
        return success(rows);
    }

    @PostMapping("/productType/queryAllList")
    public R queryAllVendorProductTypeList(@RequestBody VendorProductTypeRequest request) {
        Rows<VendorProductTypeDTO> rows = vendorProductTypeService.queryAllVendorProductTypeList(request);
        return success(rows);
    }

    @PostMapping("/productType/detail")
    public R<VendorProductTypeDTO> vendorProductTypeDetail(@RequestBody VendorProductTypeRequest request) {
        VendorProductTypeDTO vendorProductType = vendorProductTypeService.vendorProductTypeDetail(request.getId());
        return success(vendorProductType);
    }

    @PostMapping("/productType/edit")
    public R editVendorProductType(@RequestBody VendorProductTypeDTO request) {
        vendorProductTypeService.editVendorProductType(request);
        return success();
    }

    @PostMapping("/productType/delete")
    public R deleteVendorProductType(@RequestBody VendorProductTypeRequest request) {
        vendorProductTypeService.deleteVendorProductType(request.getId());
        return success();
    }
}
